<?php 

namespace app\admin\model;

use think\Db;
use think\Model;

class Booking extends Model
{
    protected $table = "yzn_gd_booking";

    public static function insertCensus($jsonArr)
    {
        foreach($jsonArr as $row){
            $a = json_decode($row,true);
            foreach($a as $k=>$row){
                $census = Db::name('gd_bad_census')->where('bad_id',$row['id'])->where('addtime','>',date('Y-m-d 00:00:00'))->find();
                if(empty($census) && $row['nums'] > 0){
                    Db::name('gd_bad_census')->insertGetId([
                        'bad_id'=>$row['id'],
                        'bad_title'=>$row['title'],
                        'counts'=>(int)$row['nums'],
                        'addtime'=>date('Y-m-d H:i:s')
                    ]);
                }else{
                    Db::name('gd_bad_census')->where('id',$census['id'])->update([
                        'counts'=>(int)$row['nums']+(int)$census['counts'],
                        'mdtime'=>date('Y-m-d H:i:s')
                    ]);
                }
            }
        }

    }
}